<!doctype html>
<#import "/spring.ftl" as spring />
<#assign security=JspTaglibs["/META-INF/security.tld"] />
<html lang="en">
<head>
<#include "../include/css.ftl">
</head>

<body class="adminbody">

<div class="content-page">
    <!-- Start content -->
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-xl-12">
                    <div class="breadcrumb-holder">
                        <h1 class="main-title float-left">Account</h1>
                        <ol class="breadcrumb float-right">
                            <li class="breadcrumb-item">Home</li>
                            <li class="breadcrumb-item active">Accounts</li>
                        </ol>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>
            <!-- end row -->

            <div class="row">
                <div class="col-xl-12">
                    <div class="card mb-3">

                        <div class="card-body">
                            <div class="table-responsive">
                                <table id="example" class="table table-bordered table-hover display">
                                    <thead>
                                    <tr>
                                        <th>id</th>
                                        <th>uid</th>
                                        <th>username</th>
                                        <th>enabled</th>
                                        <th>create_date</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tfoot>
                                    <tr>
                                        <th>id</th>
                                        <th>uid</th>
                                        <th>username</th>
                                        <th>enabled</th>
                                        <th>create_date</th>
                                        <th>操作</th>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>

                        </div>
                    </div><!-- end card-->
                </div>
            </div>
        </div>
        <!-- END container-fluid -->
    </div>
    <!-- END content -->
</div>
<!-- END content-page -->

<!-- END main -->
<#include "../include/js.ftl">
<script>
    $(document).ready(function () {
        var _csrf_token = $("meta[name='_csrf']").attr("content");
        var _csrf_header_name = $("meta[name='_csrf_header']").attr("content");

        $('#example').DataTable({
            serverSide: true,
            processing: true,
            ajax: {
                url: '${ctx}/accounts',
                type: 'POST',
                beforeSend: function (request) {
                    request.setRequestHeader(_csrf_header_name, _csrf_token);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    if (jqXHR.status == 440 || jqXHR.status == 403) {
                        window.parent.location.assign("${ctx}/");// 跳转到登录页面，让iframe的父页面（浏览器）跳转。
                    } else if (jqXHR.status >= 500) {
                        toastr.error('暂停服务，请耐心等待服务恢复。', '系统通知');
                    } else {
                        toastr.error('error code: ' + jqXHR.status, 'Error');
                    }
                }

            },
            columns: [
                {"data": "id"},
                {"data": "uid"},
                {"data": "username"},
                {"data": "enabled"},
                {
                    data: "create_date",
                    render: function (d) {
                        return moment(d).format("YYYY/MM/DD HH:mm");
                    }
                },
                {
                    data: "id",
                    render: function (data, type, row, meta) {
                        return ''
                                <@security.authorize access="hasPermission('','account.edit')">
                                +'<a class="btn btn-outline-primary btn-sm" href="${ctx}/accounts/edit/'+data+'" title="编辑"> <i class="fa fa-edit"></i> </a> '
                                </@security.authorize>

                                <@security.authorize access="hasPermission('','account.authority.view')">
                                + '<a class="btn btn-outline-primary btn-sm" href="${ctx}/accounts/auth/'+data+'" title="权限"> <i class="fa fa-user-secret"></i> </a>'
                                </@security.authorize>
                    }
                }
            ]
        });
    });
</script>
<!-- END Java Script for this page -->

</body>
</html>